<?php

namespace App\Entity;

use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;

/**
 * @ApiResource()
 * @ORM\Entity(repositoryClass="App\Repository\CommentRepository")
 */
class Comment
{
    /**
     * @Groups({"comment"})
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @Groups({"user"})
     * 哪个用户发起的评价
     * @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="comments")
     * @ORM\JoinColumn(nullable=false)
     */
    private $who;

    /**
     * @Groups({"comment"})
     * 评价了什么对象，这个值需要根据type来确定
     * @ORM\Column(type="smallint", nullable=true)
     */
    private $what;

    /**
     * @Groups({"comment"})
     * 评价时间
     * @ORM\Column(type="datetime")
     */
    private $createAt;

    /**
     * @Groups({"comment"})
     * 打分
     * @ORM\Column(type="float", nullable=true)
     */
    private $score;

    /**
     * @Groups({"comment"})
     * 评价内容
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $content;

    /**
     * @Groups({"comment"})
     * 有图评价
     * @ORM\Column(type="array", nullable=true)
     */
    private $pics = [];

    /**
     * 被评价主体类型，需要自己定义
     * @ORM\Column(type="smallint", nullable=true)
     */
    private $type;

    /**
     * 附属参数，有时候需要根据一些参数来确定是否可以评价
     * 比如：一个门店每消费一次，才能评价一次，那么这个时候应该传订单ID
     * 也可以保存其他参数用于后续操作
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $param;

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getWho(): ?User
    {
        return $this->who;
    }

    public function setWho(?User $who): self
    {
        $this->who = $who;

        return $this;
    }

    public function getWhat(): ?int
    {
        return $this->what;
    }

    public function setWhat(?int $what): self
    {
        $this->what = $what;

        return $this;
    }

    public function getCreateAt(): ?\DateTimeInterface
    {
        return $this->createAt;
    }

    public function setCreateAt(\DateTimeInterface $createAt): self
    {
        $this->createAt = $createAt;

        return $this;
    }

    public function getScore(): ?float
    {
        return $this->score;
    }

    public function setScore(?float $score): self
    {
        $this->score = $score;

        return $this;
    }

    public function getContent(): ?string
    {
        return $this->content;
    }

    public function setContent(?string $content): self
    {
        $this->content = $content;

        return $this;
    }

    public function getPics(): ?array
    {
        return $this->pics;
    }

    public function setPics(?array $pics): self
    {
        $this->pics = $pics;

        return $this;
    }

    public function getType(): ?int
    {
        return $this->type;
    }

    public function setType(?int $type): self
    {
        $this->type = $type;

        return $this;
    }

    public function getParam(): ?string
    {
        return $this->param;
    }

    public function setParam(?string $param): self
    {
        $this->param = $param;

        return $this;
    }
}
